home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Newton / Communications / Post Office 2.0.sit / PostOffice2.nwt < prev   
Encoding:
Text File  |  1995-05-21  |  14.2 KB  |  689 lines  |  [TEXT/NWPM]

  1. PostOffice
  2. // :doObj('add,'PostOffice)
  3. // :doObj('build,'PostOffice)
  4. // :doObj('remove,'PostOffice)
  5. {
  6. // 
  7. // (c)1994, 1995 by Serg Koren.  All rights reserved.
  8. // Do not distribute modified or NTK versions.
  9. // Shareware $8 to
  10. // 485 Brown Briar Cir.
  11. // Horsham,PA 19044-1974
  12. // 
  13.  
  14.     viewclass: 'clView,
  15.     viewFlags: vFloating + vApplication,
  16.     viewFormat: 337,
  17.     declareSelf: 'base,
  18.     title: "Post Office",
  19.     ViewBounds: RelBounds(10,5,220,100),
  20.     curEntry : {},
  21.     soupName : "Post:SKoren",
  22.     defaultEntry:  {   pho: "", loc: ""},
  23.     mySoup : nil,
  24.     soupCursor : nil,
  25.     editView : nil,
  26.  
  27.     _package: {
  28.         version: 200,
  29.         copyright: "©1994, 1995 by S.Koren.\u000D\u All rights reserved",
  30.         devSignature: "SKoren",
  31.         icon: :GetIcon("Post Office"),
  32.     },
  33.  
  34.     RegisterCardSoup: kRegisterCardSoupFunc,
  35.     UnregisterCardSoup: kUnregisterCardSoupFunc,
  36.     GetUserConfig: kGetUserConfigFunc,
  37.     SetUserConfig: kSetUserConfigFunc,
  38.     FlushUserConfig: kFlushUserConfigFunc,
  39.  
  40.     setEntry: func(entry)
  41.         curEntry := if entry then
  42.             entry
  43.         else
  44.             deepclone(defaultEntry),
  45.  
  46.     viewSetupFormScript:
  47.     func()
  48.     begin
  49.         editView := self;
  50.  
  51.         mySoup := :RegisterCardSoup(soupName, [], appSymbol, []);
  52.         soupCursor := Query(mySoup,{type: 'index}); 
  53.         :setEntry(soupCursor:entry()); 
  54.  
  55.         if StrEqual(curEntry.loc,"") then
  56.         begin
  57.             curEntry.pho := :GetUserConfig('mailPhone); 
  58.             curEntry.loc := :GetUserConfig('location.name); 
  59.             mySoup:AddToDefaultStore(curEntry);
  60.         end; 
  61.     
  62.         GetRoot().ExtrasDrawer:close();
  63.         RefreshViews();
  64.     
  65.         inherited:?viewSetupFormScript();
  66.         
  67.     end,
  68.  
  69.     viewQuitScript: func()
  70.     begin
  71.  
  72.         // close help...
  73.         if helpView then
  74.             helpView:close();
  75.         helpView := nil;
  76.  
  77.         // get rid of soup...
  78.         mySoup := soupCursor := nil;
  79.         :UnRegisterCardSoup(soupName);
  80.         inherited:?viewQuitScript();
  81.     end,
  82.  
  83.     
  84. }
  85. -----
  86. PostOffice.add+changeBtn
  87. {
  88. // set Change button
  89.  
  90.         _proto: 'protoTextButton,
  91.         viewBounds: RelBounds(115, 70, 45, 16),
  92.         text: "Change",
  93.  
  94.         buttonClickScript: func()
  95.         begin
  96.         
  97.             curEntry.loc := loc.text;
  98.             curEntry.pho := phone.text;
  99.             locPicker.labelCommands[state] := loc.text;
  100.             Picker.labelCommands[state] := phone.text;
  101.             modPicker.labelCommands[state] := loc.text & "@" & phone.text;
  102.             :Flush();
  103.         
  104.         end;
  105.  
  106. }
  107.  
  108. -----
  109. PostOffice.about+maboutText
  110. {
  111. // about text
  112.  
  113.     viewclass: 'clParagraphView,
  114.     
  115.     text: " \u000D\u " && PostOffice._package.copyright && "\u000D\u Version" && SubStr( NumberStr(PostOffice._package.version),0,1) & "." & SubStr( NumberStr(PostOffice._package.version),1,2) & "\u000D\u email:  SergK@eworld.com",
  116.     viewFlags: 3,
  117.     viewBounds: RelBounds(5,20,200,80),
  118. }
  119. -----
  120. PostOffice+SetsBtn
  121. {
  122. // button for soup set maintenance
  123.  
  124.     _proto: 'protoTextButton,
  125.     text : "Sets...",
  126.     
  127.     viewBounds: RelBounds(5,5,40,16),
  128.  
  129.     buttonClickScript:func()
  130.     begin
  131.             :setEntry(nil);
  132.             add:open();
  133.     end;
  134.     
  135. }
  136.  
  137. -----
  138. PostOffice+about
  139. {
  140. // float n go for about
  141.  
  142.         _proto:'protoFloatNGo,
  143.        viewBounds:RelBounds(0,5,200,90),
  144. }
  145.  
  146.  
  147. -----
  148. PostOffice+Status
  149. {
  150. // current setting line
  151.  
  152.         _proto: 'protoStaticText,
  153.         viewBounds: RelBounds(65,87,200,16),
  154.         text:  nil, 
  155.  
  156.         viewSetupFormScript: func()
  157.         text := :GetUserConfig('location.name) & "@" & :GetUserConfig('mailPhone),  // force update
  158.  
  159. }
  160.  
  161. -----
  162. PostOffice+picker
  163. {
  164. // phone picker
  165.  
  166.     _proto: 'protoLabelPicker,
  167.     text: "Phones",
  168.     viewBounds: RelBounds(50,50,150,16),
  169.     labelCommands: nil,
  170.         
  171.  
  172.     viewSetupFormScript: func()
  173.     begin 
  174.         labelCommands:= [];
  175.         local e, curs, soup;
  176.         soup := GetUnionSoup("Post:SKoren");
  177.         // get every phone entry...
  178.         labelCommands := MapCursor(Query(soup,{type: 'index}),func (e) e.pho);
  179.         inherited:viewSetupFormScript();
  180.     end,
  181.  
  182.     labelActionScript: func(cmd)
  183.     begin
  184.         SetValue(Status, 'text, locpicker.labelCommands[cmd] & "@" &  labelCommands[cmd] );
  185.         :SetUserConfig('location.name, locpicker.labelCommands[cmd]);
  186.         :SetUserConfig('mailPhone, labelCommands[cmd]);
  187.         :FlushUserConfig();
  188.         // switch to the one chosen...
  189.         locpicker:UpdateText(locpicker.labelCommands[cmd]);
  190.     end;
  191. }
  192.  
  193. -----
  194. PostOffice+locpicker
  195. {
  196. // location picker
  197.  
  198.     _proto: 'protoLabelPicker,
  199.     text: "Locations",
  200.     viewBounds: RelBounds(50,30,150,16),    
  201.     labelCommands: nil,
  202.  
  203.     viewSetupFormScript: func()
  204.     begin 
  205.         labelCommands:= [];
  206.         local e, curs, soup;
  207.         soup := GetUnionSoup("Post:SKoren");
  208.         // get all the locations...
  209.         labelCommands := MapCursor(Query(soup, {type: 'index}),func (e) e.loc);    
  210.         inherited:viewSetupFormScript();
  211.      end,
  212.  
  213.     labelActionScript: func(cmd)
  214.     begin
  215.  
  216.         SetValue(Status, 'text, labelCommands[cmd] & "@" & picker.labelCommands[cmd]);
  217.         :SetUserConfig('location.name, labelCommands[cmd]);            
  218.         :SetUserConfig('mailPhone, picker.labelCommands[cmd]);
  219.         :FlushUserConfig();
  220.         // switch to current...
  221.         picker:UpdateText(picker.labelCommands[cmd]);
  222.     end;
  223. }
  224.  
  225. -----
  226. PostOffice+add
  227. {
  228. // float n go for sets
  229.  
  230.     _proto:'protoFloatNGo,
  231.     viewBounds:RelBounds(0,5,200,90),
  232.     viewFlags:  512,
  233.     state : 0,    // index of modpicker
  234. }
  235.  
  236.  
  237. -----
  238. PostOffice.about+title
  239. {
  240. // about title
  241.  
  242.     _proto: 'protoStaticText,
  243.     viewBounds: RelBounds(20,10,100,16),
  244.     text: "Post Office",
  245. }
  246.  
  247.  
  248. -----
  249. PostOffice.add+label1
  250. {
  251. // label
  252.  
  253.     _proto: 'protoStaticText,
  254.     viewBounds: RelBounds(5,30,100,16),
  255.     text: "Location:",
  256. }
  257.  
  258.  
  259. -----
  260. PostOffice.add+label2
  261. {
  262. // label
  263.     
  264.     _proto: 'protoStaticText,
  265.     viewBounds: RelBounds(5,50,100,16),
  266.     text: "Phone:",
  267. }
  268.  
  269.  
  270. -----
  271. PostOffice.InputLineproto
  272. {
  273. // my proto for input
  274.  
  275.     _proto: 'protoInputLine,
  276.     text: "",
  277.     value: 0,
  278.  
  279.  
  280.     viewSetupFormScript: func()
  281.     begin    
  282.         self.text := clone(curEntry.(field)); // clone the field's "field" slot.
  283.         inherited:?viewSetupFormScript();
  284.     end;
  285. }
  286.  
  287. -----
  288. PostOffice.add+Loc
  289. {
  290. // location input line
  291.  
  292.     _proto: 'InputLineproto,        
  293.     viewBounds: RelBounds(60,20,130,30),
  294.     viewFlags: 6657,
  295.     field: 'loc,    // create a slot which points to loc
  296.  
  297. }
  298.  
  299. -----
  300. PostOffice.add+Phone
  301. {
  302. // phone input line
  303.  
  304.     _proto: 'InputLineproto,        
  305.     viewBounds: RelBounds(60,40,130,30),
  306.     viewFlags: 10753,
  307.     field: 'pho, // create a slot which points to pho
  308.  
  309. }
  310.  
  311. -----
  312. PostOffice.Flush
  313. func()
  314. begin
  315. // flushes soup entries
  316.  
  317.     if isSoupEntry(curEntry) then
  318.         EntryChange(curEntry)
  319.     else
  320.         mySoup:AddToDefaultStore(curEntry);
  321. end
  322.  
  323. -----
  324. PostOffice.add+modpicker
  325. {
  326. // set picker
  327.  
  328.     _proto: 'protoLabelPicker,
  329.     text: "-",
  330.     viewBounds: RelBounds(30,5,200,16),
  331.     labelCommands: nil,
  332.  
  333.     viewSetupFormScript: func()
  334.     begin 
  335.         labelCommands:= [];
  336.         local e, curs, soup;
  337.         soup := GetUnionSoup("Post:SKoren");
  338.         // get all locations and phones...
  339.         labelCommands := MapCursor(Query(soup,{type: 'index}), func(e) e.loc & "@" & e.pho);
  340.         inherited:viewSetupFormScript();
  341.     end,
  342.  
  343.     
  344.     labelActionScript: func(cmd)
  345.     begin
  346.         local e, curs, soup;
  347.         soup := GetUnionSoup("Post:SKoren");
  348.         curs := Query(soup, {type: 'index});
  349.         state := cmd;
  350.             
  351.         curs:Move(cmd);    // move to selected entry in soup
  352.         e:= curs:Entry();    
  353.         SetValue(phone, 'text,clone(e.pho));
  354.         SetValue(loc,'text, clone(e.loc));    
  355.     end;
  356. }
  357.  
  358. -----
  359. PostOffice.add+addBtn
  360. {
  361. // multistate New button...
  362. // ...function dependant on btn text
  363. // ...btn text set by other buttons.
  364.  
  365.     _proto: 'protoTextButton,
  366.     viewBounds: RelBounds(5, 70, 45, 16),
  367.     text: "New",
  368.  
  369.     buttonClickScript: func()
  370.     begin 
  371.         local e, curs, soup;
  372.         if StrEqual(text, "New") then
  373.         begin
  374.             // default...clear the inputs 
  375.             // ...and get ready to add.
  376.             phone.text := "";
  377.             loc.text := "";
  378.             text := "Add";
  379.             SetValue(self,'text,"Add");
  380.             SetValue(delBtn,'text,"Cancel");
  381.             changeBtn:Hide();
  382.         end
  383.         else if StrEqual(text, "Confirm") then
  384.         begin
  385.             // delete the entry the modpicker points to...
  386.             soup := GetUnionSoup("Post:SKoren");
  387.             curs := Query(soup, {type: 'index});
  388.                 
  389.             curs:Move(state);    // move to entry in modpicker
  390.             e:= curs:Entry();    
  391.             if isSoupEntry(e) then
  392.                 EntryRemoveFromSoup(e);
  393.             SetValue(self,'text,"New");
  394.             SetValue(delBtn,'text,"Delete");
  395.             changeBtn:Show();    
  396.             // remove the corresponding entries in the pickers...            
  397.             ArrayRemoveCount(modpicker.labelCommands, state,1);
  398.             ArrayRemoveCount(locpicker.labelCommands, state,1);
  399.             ArrayRemoveCount(picker.labelCommands, state,1); 
  400.             modpicker:UpdateText(modpicker.labelCommands[0]);
  401.         end
  402.         else
  403.         begin 
  404.             // add...we've entered stuff into input lines...
  405.             :setEntry(nil);
  406.             curEntry.loc := loc.text;
  407.             curEntry.pho := phone.text;
  408.             :Flush();
  409.             // add the info to all the pickers...
  410.             AddArraySlot(locpicker.labelCommands, loc.text);        AddArraySlot(picker.labelCommands, phone.text);
  411.             AddArraySlot(modpicker.labelCommands, loc.text & "@" & phone.text);
  412.             SetValue(self,'text,"New");
  413.             SetValue(delBtn,'text,"Delete");
  414.             changeBtn:Show();
  415.         end;
  416.     end;
  417.  
  418. }
  419.  
  420. -----
  421. PostOffice.add+delBtn
  422. {
  423. // set Delete button
  424.  
  425.     _proto: 'protoTextButton,
  426.     viewBounds: RelBounds(60, 70, 45, 16),
  427.     text: "Delete",
  428.  
  429.     buttonClickScript: func()
  430.     begin
  431.         if StrEqual(text, "Delete") then
  432.         begin
  433.             SetValue(self,'text,"Cancel");                    SetValue(addBtn,'text,"Confirm");
  434.             changeBtn:Hide();
  435.         end
  436.         else
  437.         begin
  438.             SetValue(self,'text,"Delete");
  439.             SetValue(addBtn,'text,"New");
  440.             changeBtn:Show();
  441.         end;
  442.     end;
  443.  
  444. }
  445.  
  446. -----
  447. PostOffice+stat
  448. {
  449. // protostatus line
  450.  
  451.     _proto: 'protoStatus, 
  452.  
  453.     // func used to position buttons
  454.     ButtonBounds: func(width)
  455.     begin
  456.         local left1 := 25, top := 2, spacing := 6, bottom := 15;
  457.  
  458.         if width > 0 then
  459.             SetBounds(spacing,top,spacing+width,bottom)
  460.         else
  461.             SetBounds(left1,top,left1 - width,bottom);
  462.     end,
  463.  
  464. }
  465.  
  466. -----
  467. PostOffice.stat+helpBtn
  468. {
  469. // help button on protostatus
  470.  
  471.     _proto: 'protoTextButton,
  472.     viewBounds: :ButtonBounds(10),
  473.     text: "?",
  474.     viewJustify: 8389638,
  475.  
  476.     buttonClickScript: func()
  477.     :openHelp(),
  478.  
  479. }
  480.  
  481. -----
  482. PostOffice.stat+aboutBtn
  483. {
  484. // about button on protostatus
  485.  
  486.     _proto: 'protoTextButton,
  487.     viewBounds: :ButtonBounds(-10),    
  488.     text: "!",
  489.  
  490.     buttonClickScript: func()
  491.     about:open(),
  492. }
  493.  
  494. -----
  495. PostOffice.helpStuff~
  496. {
  497. // help setup
  498.  
  499.     helpBook: :helpBookTemplate(),
  500.     helpView: nil,
  501.     
  502.     openHelp: func()
  503.         if helpBook then
  504.         begin
  505.             if not helpView then
  506.                 helpView := BuildContext(
  507.                     { _proto: GetRoot().TinyTim._proto,
  508.                     bookRef: helpBook
  509.                     });
  510.             GetRoot().TinyTim:close();
  511.             helpView:openManual(helpBook);
  512.         end,
  513.  
  514.     
  515. }
  516.  
  517.  
  518. -----
  519. PostOffice.helpBook+Page1
  520. .# first help book page
  521. .subject 1
  522. About Post Office
  523. .story
  524. Post Office lets you maintain multiple NewtonMail phone numbers and corresponding locations.  
  525.  
  526.  
  527. It lets you easily switch between sets of these as you travel or commute.
  528.  
  529. -----
  530. PostOffice.helpBook+Page2
  531. .subject 1
  532. Main View
  533. .story
  534. The Post Office main view, is the one you see when you start the app.  It contains two pickers, a status line, a "Sets..." button, and 2 buttons on the status line.
  535.  
  536. -----
  537. PostOffice.helpBook+Page3
  538. .subject 1
  539. Main View Objects
  540. .story
  541. - The "Sets..." button takes y ou to the Sets View.
  542. - The "!" brings up an about box with version information.
  543. - The "?" brings up this help.
  544. - The Status line displays the current NewtonMail information.
  545. - The Location picker allows you to select a NewtonMail set by its location.
  546. - The Phone picker allows you to select a NewtonMail set by its access number
  547.  
  548.  
  549. -----
  550. PostOffice.helpBook+Page4
  551. .subject 1
  552. What Are Sets?
  553. .story
  554. A "set" as defined by Post Office is a NewtonMail access phone number and the corresponding location.
  555.  
  556.  
  557. Post Office lets you maintain sets.
  558.  
  559. -----
  560. PostOffice.helpBook+Page5
  561. .subject 1
  562. Sets View
  563. .story
  564. The Post Office sets view is where you maintain access location and numbers for NewtonMail.  This view consists of one picker, two input lines, and three buttons.
  565.  
  566. -----
  567. PostOffice.helpBook+Page6
  568. .subject 1
  569. Sets View Objects
  570. .story
  571. -The picker allows you to select which existing set you wish to change or delete.
  572. -The two input lines allow you to add new sets or modify the information in an existing one.
  573. -The three buttons are "New", "Delete" "Change", and perform the function as labelled.
  574.  
  575.  
  576. -----
  577. PostOffice.helpBook+Page7
  578. .subject 1
  579. How Do I Add A New Set?
  580. .story
  581. -Scrub out the information in the input lines.
  582. -Enter the new information.
  583. -Click the "New" button.
  584. -Confirm by clicking the "Add" button.
  585.  
  586. -----
  587. PostOffice.helpBook+Page8
  588. .subject 1
  589. How Do I Delete A Set?
  590. .story
  591. -Select the set to be deleted from the picker
  592. -Click the "Delete" button.
  593. -Confirm by clicking the "Confirm" button.
  594.  
  595. -----
  596. PostOffice.helpBook+Page9
  597. .subject 1
  598. How Do I Change A Set?
  599. .story
  600. -Select the set to be changed from the picker
  601. -Enter the modified information in the input lines.
  602. -Click the "Change" button.
  603.  
  604. -----
  605. PostOffice.helpBook+Page91
  606. .subject 1
  607. About Newt 3.0
  608. .story
  609. Post Office was written using Newt 3.0 by Steve Weyer.
  610.  
  611. "Newt 3.0
  612. a native development environment for simple applications using NewtonScript, and for creating turtle-like graphics using gestures, buttons, and NS. "
  613.  
  614. Newt 3.0 runs on your Newton and produces standalone packages without a desktop computer.
  615.  
  616. Steve Weyer - weyer@netaxs.com
  617. -----
  618. PostOffice.helpBook+Page92
  619. .subject 1
  620. About The Author
  621. .story
  622. Serg Koren
  623. 485 Brown Briar Cir.
  624. Horsham, PA 19044-1974
  625.  
  626. Post Office is shareware: $8
  627.  
  628. SergK@eworld.com
  629. archimag@netaxs.com
  630. WizLord@aol.com
  631. http://www.netaxs.com/~archimag/Newton.html
  632.  
  633. -----
  634. PostOffice.helpBook+Page93
  635. .subject 1
  636. Disclaimers & Limitations
  637. .story
  638. Post Office is provided as is. 
  639. Post Office creates a soup called "Post:SKoren".
  640. Post Office also modifies the userConfiguration soup.
  641.  
  642.  
  643. -----
  644. GetIcon
  645. func(which)
  646. begin
  647.     
  648.         local iconsoup := GetUnionSoup("Icons:BenG");
  649.         local entry :=  (cursor := Query(iconsoup, {type: 'index})):entry();
  650.  
  651.         while entry do
  652.         begin
  653.  
  654.             if StrEqual(entry.name, which) then 
  655.                 return entry.icon;
  656.  
  657.             entry := cursor:Next();
  658.             
  659.         end;
  660.  
  661.         return nil;
  662. end
  663. -----
  664. PostOffice.helpBook+Page94
  665. .subject 1
  666. Registration
  667. .story
  668. Post Office is shareware.
  669. Please send $8 if you find this useful to:
  670.  
  671. Serg Koren
  672. 485 Brown Briar Cir.
  673. Horsham, PA 19044-1974
  674.  
  675.  
  676. -----
  677. _PostOffice._about+title
  678.  {
  679. // about box title
  680.  
  681.     _proto: 'protoStaticText,
  682.     viewBounds: RelBounds(20,20,100,16),
  683.     text: "   Post Office",
  684. }
  685.  
  686.  
  687.  
  688. -----
  689.